package com.gs.api.config;

import com.gs.api.core.interceptor.RefererInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @author guoyunfei on 2021/7/11 20:57
 * @className WebConfig
 * @description TODO
 * @Version 1.0
 */

@Component
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private FilesConfig filesConfig;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //添加静态文件可直接访问
        registry.addResourceHandler("/api/**").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/files/**").addResourceLocations("file:///" + filesConfig.getUploadPath());
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");

    }

    //@Bean
    //public RefererInterceptor refererInterceptor() {
        //return new RefererInterceptor();
    //}

    /**
     * 注册拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //referer拦截
        //registry.addInterceptor(refererInterceptor());
    }


}
